Skip to content

build: remove duplicate C++ standard flags from LIEF#62682

Open
om-ghante wants to merge 2 commits intonodejs:mainfrom
om-ghante:fix/62129-lief-duplicate-cpp-standard-flags
Open

build: remove duplicate C++ standard flags from LIEF#62682
om-ghante wants to merge 2 commits intonodejs:mainfrom
om-ghante:fix/62129-lief-duplicate-cpp-standard-flags

Conversation

@om-ghante
Copy link
Copy Markdown

@om-ghante om-ghante commented Apr 10, 2026

LIEF's lief.gyp explicitly sets -std=gnu++17 in cflags_cc and
xcode_settings, while common.gypi already sets -std=gnu++20
project-wide. This results in both flags being passed to the compiler
(-std=gnu++20 -std=gnu++17). Since the last flag wins, LIEF was
silently compiling as C++17 instead of the intended project-wide C++20.

Additionally, upgrading LIEF to C++20 triggered compile-time conflicts in Section.cpp on modern compilers (like GCC 14 and Xcode 16.4) due to overlapping definitions between {fmt} and C++20 std::format.

Changes

  • Removed -std=gnu++17 from cflags_cc and xcode_settings.OTHER_CPLUSPLUSFLAGS.
  • Removed the msvs_settings LanguageStandard: stdcpp17 override.
  • Removed the now-inaccurate comment about needing C++17.
  • Fixed C++20 compilation failures: Removed using namespace fmt; and explicitly qualified fmt::format and fmt::join inside deps/LIEF/src/PE/Section.cpp. Joined sequence views are now cleanly materialized into std::string objects prior to formatting. This completely prevents the compiler from evaluating {fmt} function calls under C++20's strict std::format compile-time rules, resolving the CI build crash on Linux ARM, macOS, and Windows.

Why C++20 is safe for LIEF

SPDLOG_USE_STD_FORMAT is not defined in the build, so spdlog uses its
bundled fmt library rather than <format>, avoiding any C++20 conflicts once the Section.cpp syntax is properly isolated.

Risk

LIEF was previously compiling as C++17 (last flag wins). With this change it
will compile as C++20. While C++20 is a superset, reviewers should confirm
no subtle deprecations or narrowing issues arise.

Note: A separate stray debug string issue in the same file is addressed
in PR #62683.

Fixes: #62129

LIEF's lief.gyp explicitly sets -std=gnu++17 in cflags_cc and
xcode_settings, while common.gypi already sets -std=gnu++20
project-wide. This results in both flags being passed to the compiler
(-std=gnu++20 -std=gnu++17). Since the last flag wins, LIEF was
silently compiling as C++17 instead of the intended project-wide C++20.

Remove the explicit -std=gnu++17 flags from cflags_cc and
xcode_settings.OTHER_CPLUSPLUSFLAGS, and the msvs_settings
LanguageStandard override (stdcpp17), so LIEF uses the project-wide
C++20 standard. LIEF is compatible with C++20 because
SPDLOG_USE_STD_FORMAT is not defined, so spdlog uses its bundled fmt
library rather than std::format, avoiding any C++20 conflicts.

Note: a separate issue with a stray debug string in the defines list
is addressed in a follow-up PR.

Fixes: nodejs#62129
@nodejs-github-bot
Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/gyp
  • @nodejs/security-wg
  • @nodejs/single-executable

@nodejs-github-bot nodejs-github-bot added dependencies Pull requests that update a dependency file. needs-ci PRs that need a full CI run. labels Apr 10, 2026
When building LIEF with C++20 standard, the unqualified calls
to `format` and `join` in `Section.cpp` conflict with the C++20
`std::format` header provided by libstdc++ and MSVC. `std::format`
attempts to evaluate these calls at compile time but fails because
`fmt::join_view` is not a valid `std::formatter` type.

Explicitly use `fmt::format` and `fmt::join`, and convert the joined
views into `std::string` values prior to passing them into the final
formatting calls to prevent the compiler from instantiating `std::format`.

Fixes CI build failures on Linux ARM, macOS, and Windows.

Refs: nodejs#62682
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LIEF is built with two C++ standard version flags

2 participants